import java.lang.reflect.Array;
import java.util.Arrays;

public class Test {

    //数组引用  数组拷贝  数组变为字符串  数组扩容,拷贝  数组判断  数组填充

    public static void main1(String[] args) {   //数组引用
        int[] arr1={1,2,3,4};
        int[] arr2={11,22,33,44};
        arr2[0]=99;
        arr1=arr2;
        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));
    }

    public static void main2(String[] args) {//数组引用
        int[] arr1={1,2,3,4};
        int[] arr2={11,22,33,44};
        arr1[0]=99;
        arr1=arr2;
        arr2[0]=100;
        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));
    }



    public static void main3(String[] args) {  //数组引用
        int[] array={1,2,3,4,5,6};//0x11
        int[] ret=grow(array);
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(ret));
    }
    public static int[] grow(int[] array) {
        for(int i=0;i<array.length;i++)
        {
            array[i]=array[i]*2;
        }
        return array;
    }


    public static void main4(String[] args) {  //数组引用
        int[] arr={1,2,3,4};
        System.out.println(Arrays.toString(arr));
        int[] arr1=arr;
        System.out.println(Arrays.toString(arr1));
        int[] arr2=new int[arr.length];

    }

    public static void main6(String[] args) {//数组变为字符串
        int[] array={1,2,3,4};

        System.out.println(myToSring(array));
    }

    public static String  myToSring(int[] array) {
        if (array == null) {
            return "null";

        }
        String ret="[ ";
        for(int i=0;i<array.length;i++)
        {
            ret=ret+array[i];
            if(i!= array.length-1)
            {
                ret=ret+',';
            }
        }
        ret=ret+" ]";
        return ret;
    }


    public static void main(String[] args) {//数组拷贝
        int[] array={1,2,3,4};
        int[] ret=Arrays.copyOf(array,array.length);
        System.out.println(Arrays.toString(array));
        System.out.println();
        System.out.println(Arrays.toString(ret));
        System.out.println();
        int[] arr=array.clone();
        System.out.println(Arrays.toString(arr));
    }


    public static void main7(String[] args) {  //数组扩容,拷贝
        int[] array={1,2,3,4,5};
        int[] ret=Arrays.copyOf(array,array.length*2);// 数组扩容
        System.out.println(Arrays.toString(array));
        System.out.println();
        System.out.println(Arrays.toString(ret));
        System.out.println();
        //数组拷贝
        int[] copy=new int[array.length];
        System.arraycopy(ret,4,copy,0,array.length);
        System.out.println(Arrays.toString(copy));
        System.out.println();
        System.arraycopy(array,0,ret,4,array.length);
        System.out.println(Arrays.toString(ret));
        System.out.println();
        //数组拷贝范围
        int[] arr= Arrays.copyOfRange(array,1,3);
        System.out.println(Arrays.toString(arr));//[1.3)
    }


    public static void main8(String[] args) {//数组判断
        int[] array={1,2,3,4,5};
        int[] ret  ={1,2,3,4,5};
        int[] arr1={1,2,3,4};
        System.out.println(Arrays.equals(array,ret));
        System.out.println(Arrays.equals(array,arr1));
    }

    public static void main9(String[] args) {//数组填充
        int[] array=new int[10];
        //Arrays.fill(array,-1);
        Arrays.fill(array,1,3,-1);//[1,3）
        System.out.println(Arrays.toString(array));
    }


}

